//
//  MapWebViewController.m
//  PerfectWorld
//
//  Created by dllo on 16/9/2.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "MapWebViewController.h"
#import "NetworkHandler.h"
#import "StrategyList.h"
#import "Masonry.h"
#import "FreeDesignWebViewController.h"
#import "UMSocial.h"
#import "LoginLeftViewController.h"
#import "ReviewViewController.h"
#import "NSString+LSTMD5.h"
@interface MapWebViewController ()
@property (nonatomic, strong)NSString *str;
@property (nonatomic, strong)UILabel *leftLabel;
@property (nonatomic, strong)UILabel *rightLabel;
@property (nonatomic, strong)UIButton *bigBtn;
@end

@implementation MapWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    [self createWebView];
    [self creatSubView];
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(5, 15, 35, 30);
    [leftBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
        [self.view addSubview:leftBtn];
    [leftBtn addTarget:self action:@selector(clickLeftBtn:) forControlEvents:UIControlEventTouchUpInside];
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(self.view.frame.size.width - 40, 15, 35, 30);
    [rightBtn setImage:[UIImage imageNamed:@"分享"] forState:UIControlStateNormal];
    [self.view addSubview:rightBtn];
    [rightBtn addTarget:self action:@selector(clickRightBtn:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)createWebView
{
    UIWebView *webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 50)];
    webview.scalesPageToFit = YES;
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://m.guju.com.cn/release/views/gonglue/?id=%@", _urlStr]]]];
    [self.view addSubview:webview];
}
- (void)creatSubView {
    UIView *bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.width.mas_equalTo(self.view);
        make.height.mas_equalTo (50);
     }];
    self.leftLabel = [[UILabel alloc] init];
    _leftLabel.text = @"36";
    [self.view addSubview:_leftLabel];
    [_leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.bottom.mas_equalTo(bottomView);
        make.width.mas_equalTo(self.view.bounds.size.width / 8);
        make.left.mas_equalTo (self.view.bounds.size.width / 8 );
    }];
    _rightLabel = [[UILabel alloc] init];
    _rightLabel.text = @"15";
    [self.view addSubview:_rightLabel];
    [_rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.bottom.mas_equalTo(bottomView);
        make.width.mas_equalTo(self.view.bounds.size.width / 8);
        make.left.mas_equalTo (self.view.bounds.size.width / 3);
    }];
    _bigBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_bigBtn setTitle:@"免费设计" forState:UIControlStateNormal];
    _bigBtn.backgroundColor = [UIColor colorWithRed:0.15 green:0.33 blue:0.59 alpha:1.00];
    [self.view addSubview:_bigBtn];
    [_bigBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_bigBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo (self.view.bounds.size.width / 2);
        make.height.bottom.mas_equalTo(bottomView);
        make.left.mas_equalTo(self.view.bounds.size.width / 2);
    }];
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"小心"] forState:UIControlStateNormal];
    [self.view addSubview:btn1];
    [btn1 addTarget:self action:@selector(clickBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo (20);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo (25);
        make.centerY.mas_equalTo (_leftLabel);
    }];
    // 评论
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"小对话"] forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [btn2 addTarget:self action:@selector(clickBtn2:) forControlEvents:UIControlEventTouchUpInside];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.bottom.mas_equalTo (btn1);
        make.left.mas_equalTo (self.view.bounds.size.width / 4);
    }];
}
- (void)handCollectionData {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [user objectForKey:@"dic"];
    NSString *secret = [dic objectForKey:@"secret"];
    NSString *key = [dic objectForKey:@"key"];
    NSString *userID = _urlStr;
    NSLog(@"userID = %@", userID);
    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval timeInterVal = [date timeIntervalSince1970];
    // 时间戳
    NSString *strTimer = [NSString stringWithFormat:@"%.0f", timeInterVal];
   //  NSString *str32 = [.text stringWith32BitMD5Lower];
    NSString *strUrl = [NSString stringWithFormat:@"http://api.guju.com.cn/v2/strategy/toLike/%@?type=1", userID];
    NSString *strBody = [NSString stringWithFormat:@"datestamp=%@&id=%@&key=%@&secret=%@", strTimer, userID, key, secret];
    NSLog(@"body = %@", strBody);
    [NetworkHandler getDataByUrlString:strUrl BodyString:strBody WithDataBlock:^(id result) {
        NSLog(@"收藏请求%@", result);
    }];
}
- (void)clickBtn:(UIButton *)sender {
    FreeDesignWebViewController *freeDesignWebVC = [[FreeDesignWebViewController alloc] init];
    [self.navigationController pushViewController:freeDesignWebVC animated:YES];
}
- (void)clickLeftBtn:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
// 收藏
- (void)clickBtn1:(UIButton *)sender {
     NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [user objectForKey:@"dic"];
    NSString *userName = dic[@"user"][@"userName"];
    if (userName.length > 0) {
        [self handCollectionData];
    } else {
        LoginLeftViewController *VC = [[LoginLeftViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }
   }
// 评论 Review
- (void)clickBtn2:(UIButton *)sender {
    ReviewViewController *reviewVC = [[ReviewViewController alloc] init];
    [self.navigationController pushViewController:reviewVC animated:YES];
    
    
}
// 分享
- (void)clickRightBtn:(UIButton *)sender {
    NSURL *url = [NSURL URLWithString:self.urlStr];
    NSString *string = [NSString stringWithFormat:@"%@", url];
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"55e85cb9e0f55af6ba0061c1"
                                      shareText:string
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToTencent,UMShareToRenren,UMShareToSina,UMShareToQzone,UMShareToEmail,UMShareToFacebook,UMShareToDouban,UMShareToSms,UMShareToQQ,nil]
                                       delegate:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
